#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define endl "\n"
using PII = pair<int, int>;
using TII = tuple<int, int, int>;
#define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FOR2(i, a, b, c) for (int i = (int)(a); i <= (int)(b); i += c)
#define FORD(i, b, a) for (int i = (int)(a); i >= (int)(b); i--)
#define FORD2(i, b, a, c) for (int i = (int)(a); i >= (int)(b); i -= c)
#define BSI basic_string<int>
#define BSPI basic_string<PII>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define VI vector<int>
#define VII vector<vector<int>>
#define VPII vector<PII>
#define lowbit(x) ((x)&(-x))
#define RE return;
#define RET return true;
#define REF return false;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;
#define pb push_back
#define fi first
#define se second
#define sz size()
constexpr int N = 1e3 + 10;
constexpr int mod = 998244353;

int __FAST_IO__ = [](){
    ios::sync_with_stdio(0), cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    return 0;
}();

int n,m;
char s[N][N];
int sx,sy;
struct E{
    int x,y;
};
array<int,3> pre[N][N];
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
char p[]={'U','R','D','L'};
string t;

void dfs(int x,int y){
    if(x==sx&&y==sy)RE;
    auto [sx,sy,i]=pre[x][y];
    dfs(sx,sy);
    t+=p[i];
}

void solve() {
    cin>>n>>m;

    queue<E>q;

    FOR(i,1,n){
        FOR(j,1,m){
            cin>>s[i][j];
            if(s[i][j]=='A'){
                sx=i,sy=j;
            }
            if(s[i][j]=='M'){
                q.push({i,j});
            }
        }
    }

    q.push({sx,sy});

    while(q.sz){
        auto [x,y]=q.front();
        q.pop();

        if(s[x][y]=='A'&&(x==n||y==m||x==1||y==1)){
            YES;

            dfs(x,y);
            cout<<t.sz<<endl;
            cout<<t;
            RE;
        }

        FOR(i,0,3){
            int a=dx[i]+x,b=dy[i]+y;
            if(a<1||b<1||a>n||b>m||s[a][b]!='.')continue;
            s[a][b]=s[x][y];
            if(s[a][b]=='A'){
                pre[a][b]={x,y,i};
            }
            q.push({a,b});
        }
    }

    NO;
}

signed main() {
    int Task = 1;
    for (; Task; Task--) {
        solve();
    }
    return 0;
}